package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.News;
import cn.wolfcode.trip.base.query.NewsQueryObject;
import cn.wolfcode.trip.base.service.INewsContentService;
import cn.wolfcode.trip.base.service.INewsService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/news")

public class NewsController {

    @Autowired
    private INewsService newsService;

    @Autowired
    private INewsContentService contentService;

    @RequestMapping(value = "/one",method = RequestMethod.GET)
    public PageInfo one(NewsQueryObject qo){
        qo.setOrderBy("n.releaseTime desc");
        return newsService.query(qo);
    }

    @RequestMapping(value = "/many",method = RequestMethod.POST)
    public PageInfo many(NewsQueryObject qo) {
        qo.setOrderBy("n.releaseTime desc");
        qo.setState(1);
        return newsService.query(qo);
    }


    /**
     * @param id
     * 根据日报的id获取日报的文章内容
     * @return
     */
    @RequestMapping(value ="/{id}",method= RequestMethod.GET)
    public News getContentById(@PathVariable Long id){

        return  newsService.getContentById(id);
    }

    @RequestMapping(value ="/list",method= RequestMethod.GET)
    public PageInfo list(NewsQueryObject qo){
        return newsService.query(qo);
    }

    @RequestMapping(value = "/recommend",method = RequestMethod.GET)
    public PageInfo recommend(NewsQueryObject qo) {
        qo.setOrderBy("n.releaseTime desc");
        qo.setState(1);
        return newsService.query(qo);
    }


}
